<template>
  <div>
    <!--头部-->
    <div class="front-header">
      <div class="front-header-left">
        <img src="@/assets/imgs/logo.png" alt="">
        <div class="title">文件传输系统</div>
      </div>
      <div class="front-header-center">
        <div class="front-header-nav">
          <el-menu :default-active="router.currentRoute.value.path" mode="horizontal" router>
						<el-menu-item index="/front/home">首页</el-menu-item>
						<el-menu-item index="/front/person">个人中心</el-menu-item>
          </el-menu>
        </div>
      </div>
      <div class="front-header-right">
        <div v-if="!data.user.username">
          <el-button @click="router.push('/login')">登录</el-button>
          <el-button @click="router.push('/register')">注册</el-button>
        </div>
        <div v-else>
          <el-dropdown>
            <div class="front-header-dropdown">
              <img :src="data.user.avatar" alt="">
              <div style="margin-left: 10px">
                <span>{{ data.user.name }}</span><el-icon><arrow-down /></el-icon>
              </div>
            </div>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="navTo('/front/myitbo')">修改密保</el-dropdown-item>
                <el-dropdown-item @click="navTo('/front/password')">修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </div>
    <!--主体-->
    <div class="main-body">
      <router-view ref="child" @updateUser="updateUser" />
      <div style="background-color: #3c3c3c; min-height: 400px; margin-top: 160px">
        <div style="width: 50%;margin: 0 auto;display: flex;color: #c2c2c2">
          <div style="flex: 1;margin-top: 20px">
            <div style="padding: 10px 0; font-size: 18px">文件传输系统</div>
            <div style="padding: 5px 0">上亿用户精选系统</div>
            <div style="padding: 5px 0">100+ 用户注册</div>
            <div style="padding: 5px 0">1,000+ 数据传输</div>
            <div style="padding: 5px 0">760,000,000 次文件下载</div>
            <div style="padding: 5px 0">380,000 MB存储</div>
          </div>
          <div style="flex: 1;margin-top: 20px">
            <div style="padding: 10px 0; font-size: 18px">关于我们</div>
            <div style="padding: 5px 0">关于文件传输系统联系我们</div>
            <div style="padding: 5px 0">隐私政策商标声明</div>
            <div style="padding: 5px 0">服务协议</div>
            <div style="padding: 5px 0">文件传输系统服务协议</div>
            <div style="padding: 5px 0">网络信息侵权通知指引</div>
            <div style="padding: 5px 0">文件传输系统服务监督员</div>
            <div style="padding: 5px 0">网站地图加入文件传输系统</div>
          </div>
          <div style="flex: 1;margin-top: 20px">
            <div style="padding: 10px 0; font-size: 18px">文件传输服务</div>
            <div style="display: flex">
              <div style="flex: 1;padding: 10px 0">下载攻略</div>
              <div style="flex: 1;padding: 5px 0">好友查看</div>
            </div>
            <div style="display: flex">
              <div style="flex: 1;padding: 10px 0">添加好友</div>
              <div style="flex: 1;padding: 5px 0">文件总转</div>
            </div>
            <div style="display: flex">
              <div style="flex: 1;padding: 10px 0">网站指南</div>
              <div style="flex: 1;padding: 5px 0">网站资讯</div>
            </div>
            <div style="display: flex">
              <div style="flex: 1;padding: 10px 0">APP下载</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

<script setup>
import {reactive} from "vue";
import router from "@/router";

const data = reactive({
  user: JSON.parse(localStorage.getItem("xm-user") || '{}'),
})

const updateUser = () => {
  data.user = JSON.parse(localStorage.getItem('xm-user') || '{}')   // 重新获取下用户的最新信息
}

// 退出登录
const logout = () => {
  localStorage.removeItem("xm-user");
  router.push("/login");
}

const navTo = (url) => {
  location.href = url
}
</script>

<style scoped>
  @import "@/assets/css/front.css";
</style>